-- David Siegel, Jonathan Coveney, HW #8

module Testing (quickcheck
               ) where

import Term

import Monad
import Test.QuickCheck

------------------------------------------------------------
-- Typeclasses
------------------------------------------------------------

instance Arbitrary Term where
    arbitrary = sized arbTerm
    coarbitrary = error "not implemented"

------------------------------------------------------------
-- Public method declarations
------------------------------------------------------------

-- This is from an earlier assignment. It runs a QuickCheck test...
quickcheck :: Testable a => a -> IO ()

------------------------------------------------------------
-- Private method declarations
------------------------------------------------------------

maxTermSize = 3

-- Arbitrary Term generator (bounded by size maxTermSize)
arbTerm :: Int -> Gen Term

------------------------------------------------------------
-- Public method definitions
------------------------------------------------------------

quickcheck = check (defaultConfig { configEvery = \n args -> "" })

------------------------------------------------------------
-- Private method definitions
------------------------------------------------------------

arbTerm n
    | n > maxTermSize = arbTerm maxTermSize
    | n <= 0 = oneof $ map (return.Literal) ['A'..'E']
    | otherwise = frequency
                    [(1, arbTerm 0),
                     (3, liftM  Not (arbTerm n)),
                     (5, liftM2 And (arbTerm (n-1)) (arbTerm (n-1))),
                     (5, liftM2 Or  (arbTerm (n-1)) (arbTerm (n-1))),
                     (2, liftM2 If  (arbTerm (n-1)) (arbTerm (n-1))),
                     (1, liftM2 Iff (arbTerm (n-2)) (arbTerm (n-2)))
                    ]
